package demo6;

import java.util.Comparator;

// 比较器接口
class Student111 {
    public String name;
    public int age;

    public Student111(String name, int age) {
        this.name = name;
        this.age = age;
    }


    @Override
    public String toString() {
        return "Student{" + "name='" + name + '\'' + ", age=" + age + '}';
    }
}

class AgeComparator implements Comparator<Student111> {

    @Override
    public int compare(Student111 o1, Student111 o2) {
        return o1.age - o2.age;
    }
}


public class Test2 {
    public static void main(String[] args) {
        Student111 student1 = new Student111("zhangsan", 10);
        Student111 student2 = new Student111("lisi", 10);

        AgeComparator ageComparator = new AgeComparator();
        System.out.println(ageComparator.compare(student1, student2));
    }
}
